﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BadJokeProject.Web;
using System.ServiceModel.DomainServices.Client;

namespace BadJokeProject
{
    public partial class Editor : UserControl
    {
        private Settings parent;
        private BadJokeDomainContext context = new BadJokeDomainContext();

        public Editor()
        {
            InitializeComponent();
        }

        public void SetParentWindow(Settings window)
        {
            this.parent = window;
        }

        private void Add_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            InvokeOperation insert = context.InsertNewBadJokeItem(
                new Web.Model.BadJokeItem
                {
                    Title = this.Title.Text,
                    Content = this.ItemContent.Text
                });
            insert.Completed += (s, args) =>
                {
                    if (insert.Error!=null)
                    {
                        return;
                    }

                    this.Title.Text = "";
                    this.ItemContent.Text = "";
                    this.Add.IsHitTestVisible = false;
                    this.Storyboard1.Begin();
                    this.Storyboard1.Completed += (sen, ags) => { this.Add.IsHitTestVisible = true; };
                };
        }
    }
}
